/**
 * 
 */
package com.swg.cocobox.message.internal;

import java.nio.charset.Charset;

import com.swg.cocobox.message.MessageContext;
import com.swg.cocobox.message.PrivateMessage;

/**
 * @author satriaprayoga
 *
 */
final class PrivateMessageImpl implements PrivateMessage {
	private static final long serialVersionUID = 4400105423080643167L;
	
	private String origin;
	private String content;
	private String destination;
	
	private Charset encoding;

	public PrivateMessageImpl(String origin, String content,
			String destination, Charset encoding) {
		super();
		this.origin = origin;
		this.content = content;
		this.destination = destination;
		this.encoding = encoding;
	}

	@Override
	public String getContent() {
		return content;
	}

	@Override
	public int getMode() {
		return MessageContext.PRIVATE;
	}

	@Override
	public byte[] getBytes() {
		byte[] data=null;
		StringBuilder builder=new StringBuilder();
		builder.append("{origin:"+getOrigin()+"}");
		builder.append("{destination:"+getDestination()+"}");
		builder.append("{content:"+getContent()+"}");
		builder.append("{mode:"+MessageContext.PM+"}");
		data=builder.toString().getBytes(encoding);
		return data;
	}

	@Override
	public String getDestination() {
		return destination;
	}

	@Override
	public String getOrigin() {
		return origin;
	}

}
